package com.shihan.redis.springboot.demo.controller;

import com.shihan.redis.springboot.demo.service.OrderService;
import com.shihan.redis.springboot.demo.utils.RedisUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description 模拟订单 30 分钟失效的案例代码（目前的代码还不规范，未做判空处理等，只是搭建一个业务处理逻辑）
 * @Author shihan
 * @Date 2021/1/23 20:09
 * @Version 1.0
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private RedisUtils redisUtils;

    @Autowired
    private OrderService orderService;

    @PostMapping("/create")
    public String createOrder(String orderName) {
        boolean createRes = orderService.createOrder(orderName);
        if (createRes) {
            return "订单创建成功！";
        } else {
            return "订单创建失败！";
        }
    }

    @PostMapping("/pay")
    public String payOrder(String orderId) {
        boolean res = orderService.payOrder(orderId);
        if (res) {
            return "订单支付成功！";
        } else {
            return "订单支付失败！";
        }
    }

}
